﻿@using NewLife.Web;
@{
    var page = ViewBag.Page as Pager;
    page.PageUrlTemplate = Url.Action("Index") + "{链接}";
    // 没有总记录数的时候不显示分页，可以认为不启用分页
}
@helper  GetNumericPage(Pager page, int len = 8)
{

    int left = (len - 1) / 2, right = len - left - 1;
    int start = page.PageIndex - left;//开始页数
    Int64 end = page.PageIndex + right;//结束页数
    start = start < 1 ? 1 : start;
    end = end > page.PageCount ? page.PageCount : end;
    if (page.PageIndex <= 1)
    {
        <li class="paginItem current"><a href="#">|<</a></li>
        <li class="paginItem current"><a href="#"><</a></li>
    }
    else
    {
        <li class="paginItem"><a href="@page.GetPageUrl("首页", 1)">|<</a></li>
        <li class="paginItem"><a href="@page.GetPageUrl("上一页", page.PageIndex-1)"><</a></li>
    }

    for (int i = start; i <= end; i++)
    {
        if (i == page.PageIndex)
        {
            <li class="paginItem current"><a href="javascript:;">@i</a></li>
        }
        else
        {
            <li class="paginItem"><a href="@page.GetPageUrl(i.ToString(), i)">@i</a></li>
        }
    }

    if (page.PageIndex >= page.PageCount)
    {
        <li class="paginItem current"><a href="#">></a></li>
        <li class="paginItem current"><a href="#">>|</a></li>
    }
    else
    {
        <li class="paginItem"><a href="@page.GetPageUrl("下一页", page.PageIndex + 1)">></a></li>
        <li class="paginItem"><a href="@page.GetPageUrl("未页", page.PageCount)">>|</a></li>
    }
}

@if (page.TotalCount > 0)
{
    <div class="pagin">
        <div class="message">共<i class="blue">@page.TotalCount</i>条记录，当前显示第&nbsp;<i class="blue">@page.PageIndex&nbsp;</i>页/共&nbsp;<i class="blue">@page.PageCount&nbsp;</i>页</div>
        <ul class="paginList">
            @GetNumericPage(page)
        </ul>
    </div>
}